import { AssertException } from '../exception/AssertException'

/**
 * Assert
 * @author LL
 * @date 2022-01-22 上午 12:50
 **/
export class Assert {
    /**
     * 断言 true
     * @param {boolean} status
     * @param {string} msg
     */
    public static isTrue(status: boolean, msg?: string): void {
        // noinspection SuspiciousTypeOfGuard
        if (typeof status !== 'boolean') {
            throw new TypeError('期望 boolean 类型, 实际获得 ' + status)
        }
        if (!status) {
            throw new AssertException(msg ?? '断言错误: 期望 true')
        }
    }

    /**
     * 断言 false
     * @param {boolean} status
     * @param {string} msg
     */
    public static isFalse(status: boolean, msg?: string): void {
        // noinspection SuspiciousTypeOfGuard
        if (typeof status !== 'boolean') {
            throw new TypeError('期望 boolean 类型, 实际获得 ' + status)
        }
        if (status) {
            throw new AssertException(msg ?? '断言错误: 期望 false')
        }
    }

}
